package de.lehmann.sudoku.userInterface.graphical;

import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

public class Resizer implements ComponentListener {

	@Override
	public void componentHidden(ComponentEvent event) {
		// Unused
	}

	@Override
	public void componentMoved(ComponentEvent event) {
		// Unused
	}

	@Override
	public void componentResized(ComponentEvent event) {
		SGrid src = (SGrid) event.getSource(); // Save the SGrid this method was called for as src.
		int size;
		if(src.getWidth()<src.getHeight()){
			size = src.getWidth();
			size -= (src.HEIGHT-1)*SGrid.OFFSET + src.HEIGHT*(src.WIDTH-1)*SBox.OFFSET;
		}else {
			size = src.getHeight();
			size -= (src.WIDTH-1)*SGrid.OFFSET + src.WIDTH*(src.HEIGHT-1)*SBox.OFFSET;
		}
		size /= src.SIZE;
		STile.setFont(size);
		src.adaptFont();
	}

	@Override
	public void componentShown(ComponentEvent event) {
		// Unused
	}

}
